package com.pagoda.nerp.trade.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pagoda.nerp.trade.app.vendor.dto.MdVendorGoodsDto;
import com.pagoda.nerp.trade.common.ConstantDefine;
import com.pagoda.nerp.trade.common.PageListResult;
import com.pagoda.nerp.trade.service.MdGoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.pagoda.nerp.trade.dao.MdGoodsDao;
import com.pagoda.nerp.trade.dao.MdVendorGoodsDao;
import com.pagoda.nerp.trade.entity.MdGoods;
import com.pagoda.nerp.trade.entity.MdVendorGoods;

import javax.servlet.http.HttpSession;

@Service
public class MdGoodsServiceImpl implements MdGoodsService {
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private MdGoodsDao goodsDao;

	/**
	 * 查询水果名称
	 * @param params 水果名称
	 * */
	@Override
	public List<Map<String,Object>> queryByGoodsName(Map<String,Object> params) throws Exception{
		// 1.参数处理
		String inputStr = params.get("goodsName").toString();

		// 2.查询
		List<MdGoods> mdGoodsList= goodsDao.selectByGoodsName("%" + inputStr + "%");

		// 3.判断结果集是否为空
		if (null == mdGoodsList){
			logger.debug("未搜索关键字相关水果！{}",inputStr);
			return null;
		}

		// 4.MdGoods转Map
		List<Map<String,Object>> goodsList = new ArrayList<Map<String,Object>>();
		Map<String,Object> good = null;
		for(MdGoods md : mdGoodsList){
			good = new HashMap<String,Object>();

			good.put("goodsCode", md.getGoodsCode());
			good.put("goodsName", md.getGoodsName());

			goodsList.add(good);
		}

		return goodsList;
	}

}
